package edu.stthomas.seis752.model;

// default package
// Generated Apr 11, 2013 1:36:19 AM by Hibernate Tools 3.4.0.CR1

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 * Collection generated by hbm2java
 */
@Entity
@Table(name = "collection", catalog = "jibster")
public class Collection implements java.io.Serializable {

	private Long id;
	private CollectionType collectionType;
	private long ownerId;
	private String name;
	private Set<Member> members = new HashSet<Member>(0);

	public Collection() {
	}

	public Collection(CollectionType collectionType, long ownerId) {
		this.collectionType = collectionType;
		this.ownerId = ownerId;
	}

	public Collection(CollectionType collectionType, long ownerId, String name,
			Set<Member> members) {
		this.collectionType = collectionType;
		this.ownerId = ownerId;
		this.name = name;
		this.members = members;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "type", nullable = false)
	public CollectionType getCollectionType() {
		return this.collectionType;
	}

	public void setCollectionType(CollectionType collectionType) {
		this.collectionType = collectionType;
	}

	@Column(name = "owner_id", nullable = false)
	public long getOwnerId() {
		return this.ownerId;
	}

	public void setOwnerId(long ownerId) {
		this.ownerId = ownerId;
	}

	@Column(name = "name", length = 45)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "collection")
	@Cascade({CascadeType.ALL})
	public Set<Member> getMembers() {
		return this.members;
	}

	public void setMembers(Set<Member> members) {
		this.members = members;
	}
	
	public void addMember(Member m) {
		if(this.members == null) this.members = new HashSet<Member>();
		this.members.add(m);
	}

}
